"""
@File    : run_main.py
@Author  : qve-wzy
@Time    : 2020/9/5 0005 9:19
"""
import sys
from operate_key.get_excel_dara import GetData
from operate_key.action_method import ActionMethod
from util.server import Server

class RunMain:
    '''
    运行excel case文件
    '''
    def run_method(self):
        server = Server()
        server.main()
        data = GetData() # 获取执行数据
        action_method = ActionMethod() # 获取所有操作
        lines = data.get_case_lines()
        for i in range(2, lines+1):
            handle_step = data.get_handle_step(i)
            element_key = data.get_element_key(i)
            handle_value = data.get_handle_value(i)
            expect_key = data.get_expect_element(i)
            expect_step = data.get_expect_handle(i)
            print("步骤---》",i,lines,str(handle_step))
            excute_method = getattr(action_method, str(handle_step))

            if element_key != None: # 有元素有步骤
                excute_method(element_key, handle_value)
            else: # 有步骤没元素  返回元素尚未找到
                excute_method(handle_value)

            if expect_step != None: #  有预期步骤
                expect_result = getattr(action_method, str(expect_step))
                result = expect_result(expect_key) # 根据预期步骤，传入预期数据，判断ini中有没有对应的预期结果
                print("expect_step->", expect_step)
                print("expect_key->", expect_key)
                print("resulet->", result)
                if result: # 有预期值，则说明预期正确
                    data.write_value(i,9,"PASS")
                else: # 没有，说明不正确
                    data.write_value(i,9,"FALSE")

if __name__ == '__main__':
    run = RunMain()
    run.run_method()
